package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.json.JSONObject;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.vo.DeviceDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 设备信息Controller
 * 
 * @author zzyl
 * @date 2025-10-23
 */
@RestController
@RequestMapping("/nursing/device")
@Api(tags = "设备信息相关接口")
public class DeviceController extends BaseController
{
    @Autowired
    private IDeviceService deviceService;

    /**
     * 查询设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取设备信息列表")
    public TableDataInfo<List<Device>> list(Device device)
    {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }
    /**
     * 从物联网平台同步产品列表
     */
    @PreAuthorize("@ss.hasPermi('device:device:list')")
    @PostMapping("/syncProductList")
    @ApiOperation(value = "获取设备信息列表")
    public AjaxResult list()
    {
       deviceService.syncProductList();
       return AjaxResult.success();
    }
    /**
     * 查询所有产品列表
     */
    @GetMapping("/allProduct")
    public AjaxResult allProduct(){
        return AjaxResult.success(deviceService.allProduct());
    }

    @PostMapping("/register")
    public  AjaxResult saveDevice(@RequestBody DeviceDto dto){
        deviceService.saveDevice(dto);
        return AjaxResult.success();
    }
    @PostMapping("/queryDeviceDetail")
    public AjaxResult queryDeviceDetail(@RequestBody DeviceDto dto){
       DeviceDetailVo detailVo = deviceService.queryDeviceDetail(dto);
        return AjaxResult.success(detailVo);
    }
    @PostMapping("/queryProductModelInfo")
    public AjaxResult queryProductModelInfo(@RequestBody DeviceDto dto){
        JSONObject jsonObject= deviceService.queryProductModelInfo(dto);
        return AjaxResult.success(jsonObject);
    }
    @PostMapping("/queryDevicePropertyStatus")
    public AjaxResult queryDevicePropertyStatus(@RequestBody DeviceDto dto){
        return AjaxResult.success(deviceService.queryDevicePropertyStatus(dto));
    }
    @PutMapping
    public AjaxResult updateDevice(@RequestBody DeviceDto dto){
        deviceService.updateDevice(dto);
        return AjaxResult.success();
    }
    @DeleteMapping
    public AjaxResult deleteDevice(@RequestBody DeviceDto dto){
        deviceService.deleteDevice(dto);
        return AjaxResult.success();
    }
}
